<#assign className = table.className>
<#assign classNameLower = className?uncap_first>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Autumn Admin | 用户管理</title>
		<link rel="stylesheet" href="../../../assets/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../assets/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../assets/lib/toastr/toastr.min.css" />
		<link rel="stylesheet" href="../../../assets/style/font-awesome/css/font-awesome.min.css" />
		<link rel="stylesheet" href="../../../assets/lib/select2/select2.min.css" />
		<link rel="stylesheet" href="../../../assets/lib/select2/select2-bootstrap.min.css" />
	</head>
	<body>
		<div style="padding-top: 20px;">
		<form class="layui-form" id="${classNameLower}_form" lay-filter="${classNameLower}_form">
			<input type="hidden" id="id" name="id" />
			<#list table.columns as column>
			<#if !column.pk && column.columnNameLower != 'createBy'
			&& column.columnNameLower != 'createDate' && column.columnNameLower != 'updateBy'
			&& column.columnNameLower != 'updateDate' && column.columnNameLower != 'password'
			&& column.columnNameLower != 'version'>
			<div class="layui-form-item">
				<label class="layui-form-label">${column.columnAlias!}<span style="color: red;">*</span></label>
				<div class="layui-input-inline">
					<input type="text" name="${column.columnNameLower}" id="${column.columnNameLower}" autocomplete="off" lay-verify="required" class="layui-input"/>
				</div>
			</div>
			</#if>
			</#list>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button type="button" class="layui-btn" lay-submit lay-filter="apply">提交</button>
					<button type="button" class="layui-btn layui-btn-primary" id="reset">取消</button>
				</div>
			</div>
		</form>
		</div>
		
		<!-- BEGIN CORE SCRIPTS -->
		<script src="../../../assets/layui/layui.js"></script>
		<script src="../../../assets/lib/jquery.min.js"></script>
		<script src="../../../assets/lib/jquery-extension.js"></script>
		<script src="../../../assets/lib/toastr/toastr.min.js"></script>
		<script src="../../../assets/lib/select2/select2.min.js"></script>
		<script src="../../../assets/lib/select2/select2tree.js"></script>
		<!-- END CORE SCRIPTS -->
		
		<!-- BEGIN CUSTOM SCRIPTS -->
		<script src="../../../assets/lib/common.js"></script>
		<script src="../../../assets/lib/url.js"></script>
		<script src="../../../assets/lib/menu.js"></script>
		<!-- END CUSTOM SCRIPTS -->
		
		<script>
			$(function(){

				//初始化表单
				layui.use(['form','table'],function(){
					var form = layui.form
					,table = layui.table;
					
					form.render();
					
					//提交按钮监听
					form.on('submit(apply)', function(data){
						var url = apiUrl+"/${namespace}/${classNameLower}/save";
						if(data.field.id){
						  url = apiUrl+"/${namespace}/${classNameLower}/update";
						}
						
						if(data.field.enable === "on"){
						 data.field.enable = 1; 
						}else{
						 data.field.enable = 0;  
						}
						var roleIds = $("#roleIds").val();
						data.field.roleIds = roleIds;
						
						$.when(JEE.ajax(url,data.field)).done(function(res){
							if(res){
								parent.layer.close(parent.index);
								parent.layui.table.reload("tb_data");
							}
						});
						
						return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
					});
				});				

				$("#reset").on('click',function(){
					parent.layer.close(parent.index);
				})
			});
		</script>
	</body>
</html>
